$().ready(function(){
    browserRedirect();
        //滚动条监听 导航显示隐藏
    $(window).scroll(function (){
        if ($(window).scrollTop()>200) {
            //
           $('.fixed-box').css('height','1rem')
        }
        if($(window).scrollTop()<200){
            $('.fixed-box').css('height','0')
        }
    });
    function init(){
        //banner
        getBanner(1)
        //news
        getNews();
    }
    init();
    $('#code img').attr('src',global.erweima);
    $('#index-logo').attr('src',global.indexLogo);
})
//获取banner图
function getBanner(type){
    // type 1 pc  2 phone
    getAjax('/Api/New/get_banner',function(res){
        console.log(res);
        let html = '';
        for(let i in res){
            html += '<li class="carousel-item"><img src="'+res[i].banner_img+'" alt="'+res[i].title+'"/>'
        }
        $('#banner').html(html);
        $("#carousel_1").FtCarousel({
            index:0,
            auto:true,
            time:5000,
            button:false,
            indicators: false
        });
    },{
        type:type
    })
}
//获取新闻
function getNews(){
    getAjax('/Api/New/first_jtxw_eight',function(res){
        console.log(res);
        let headLine = '<a href="news-details.html?id='+res[0].id+'">';
        headLine += '<div class="head-line-date">'+res[0].date+'</div>';
        headLine += '<div class="head-line-title">'+res[0].title+'</div>';
        headLine += '</a>';
        $('#head-line').html(headLine);
        let html = '';
        for(let i=1;i<res.length;i++){
            html += '<div class="news-item">';
            html += '<a href="news-details.html?id='+res[i].id+'">';
            html += '<div class="icon"><img src="img/icon/right-icon.png" alt=""></div>';
            html += '<div class="item-date">'+res[i].date+'</div>';
            html += '<div class="item-title">'+res[i].title+'</div>';
            html += '</a>';
            html += '</div>';
        }
        $('#news-item').html(html);
    })
}
